var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js')
Page({
    data: {
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500,
        menu: [{
                image: '/image/kaoshi.png',
                name: '考试',
                toPage: '/pages/examinationLogin/examinationLogin'
            }, {
                image: '/image/lianxi.png',
                name: '练习',
                toPage: '/pages/train/train'
            },
            // {
            //     image: '/image/certificate.png',
            //     name: '报名',
            //     toPage: '/pages/signUp/signUp'
            // },
            {
                image: '/image/baoming.png',
                name: '报名',
                toPage: '/pages/xinxiLuru/xinxilu'
            },
            {
                image: '/image/zhuanjia.png',
                name: '专家',
                toPage: '/pages/specialist/specialist'
            },
            {
                image: '/image/zhengshu.png',
                name: '证书查询',
                toPage: '/pages/out/out'
            },
            {
                image: '/image/jigou.png',
                name: '机构查询',
                toPage: '/pages/organization/organization'
            },


        ],
        current: 1,
        number: 4,
        pageNumber: 1,
        pageSize: 10
    },

    onLoad: function (options) {

    },
    onReady: function () {

    },

    onShow: function () {
        var _this = this
        _this.getBanner()
        _this.getCertificateList()
        _this.getNewsList()
        _this.getNewsList1()
        _this.getNewsList2()
        _this.getNewsList3()
        _this.getJobList()
        _this.getUnreadNum()
        _this.getrecruimeList()
    },
    //未读消息条数
    getUnreadNum: function () {
        var unreadNum = wx.getStorageSync('unreadNum')
        if (unreadNum != '' && unreadNum != 0) {
            wx.setTabBarBadge({
                index: 2,
                text: unreadNum
            })
        } else {
            wx.removeTabBarBadge({
                index: 2
            })
        }
    },
    //获取岗位列表
    getJobList: function () {
        var _this = this
        app._get(siteinfo.selJobList, {
            name: '',
            type: 0,
            number: 5,
            current: 1
        }, function (result) {
            _this.setData({
                employmentList: result.data.records
            });
        })
    },
    //更多就业
    moreEmploymentList: function (e) {
        wx.navigateToMiniProgram({
            appId: 'wx1b45dcbf9402e178',
            path: 'pages/employmentList/employmentList',
            envVersion: 'develop',
            success(res) {}
        })
    },
    getrecruimeList: function () {
        var _this = this
        app._get(siteinfo.recruimeList, {
            pageSize: 10,
            pageNumber: 1
        }, function (result) {
            _this.setData({
                employmentJob: result.data,
                // age: util.getAge(result.data.age)
            })
        })
    },
    toJobDetail: function (e) {
        wx.navigateToMiniProgram({
            appId: 'wx1b45dcbf9402e178',
            path: 'pages/employmentDetails/employmentDetails?id=' + e.currentTarget.dataset.id,
            extraData: {
                id: e.currentTarget.dataset.id
            },
            envVersion: 'develop',
            success(res) {}
        })
    },
    moreJobList: function (e) {
        wx.navigateTo({
            url: '/pages/jobWanted/jobWanted',
        })
    },
    // toOut:function(){
    //   wx.navigateTo({
    //     url: '../out/out',
    //  })
    // },
    // toOrganization:function(){
    //   wx.navigateTo({
    //     url: '../organization/organization',
    //  })
    // },
    //获取banner
    getBanner: function () {
        var _this = this
        app._get(siteinfo.selBanners, {}, function (result) {
            _this.setData({
                bannerList: result.data
            });
        })
    },
    //获取证书列表
    getCertificateList: function () {
        var _this = this
        app._get(siteinfo.selIndexCertificateList, {
            number: _this.data.number,
            current: _this.data.current
        }, function (result) {
            var res = result.data.records
            if (res.length != 0) {
                for (var i = 0; i < res.length; i++) {
                    res[i].createrDate = res[i].createrDate.substring(0, 10)
                }
            }
            _this.setData({
                certificateList: res
            });
        })
    },
    //获取信息列表-通知通告
    getNewsList: function () {
        var _this = this
        app._get(siteinfo.selNewsList, {
            firstColumn: '证书考试门户',
            columnName: '通知公告',
            number: _this.data.number,
            current: _this.data.current
        }, function (result) {
            var res = result.data.records
            if (res.length != 0) {
                for (var i = 0; i < res.length; i++) {
                    res[i].createrDate = res[i].createrDate.substring(0, 10)
                }
            }
            _this.setData({
                newsList: res
            });
        })
    },
    // //获取信息列表-政策信息
    getNewsList1: function () {
        var _this = this
        app._get(siteinfo.selNewsList, {
            firstColumn: '证书考试门户',
            columnName: '政策信息',
            number: _this.data.number,
            current: _this.data.current
        }, function (result) {
            var res = result.data.records
            if (res.length != 0) {
                for (var i = 0; i < res.length; i++) {
                    res[i].createrDate = res[i].createrDate.substring(0, 10)
                }
            }
            _this.setData({
                newsListZ: res
            });
        })
    },
    // //获取信息列表-行业信息
    getNewsList2: function () {
        var _this = this
        app._get(siteinfo.selNewsList, {
            firstColumn: '证书考试门户',
            columnName: '工作动态',
            number: _this.data.number,
            current: _this.data.current
        }, function (result) {
            var res = result.data.records
            if (res.length != 0) {
                for (var i = 0; i < res.length; i++) {
                    res[i].createrDate = res[i].createrDate.substring(0, 10)
                }
            }
            _this.setData({
                newsListH: res
            });
        })
    },

    // //获取信息列表-试点院校风采
    getNewsList3: function () {
        var _this = this
        app._get(siteinfo.selNewsList, {
            firstColumn: '证书考试门户',
            columnName: '试点院校风采',
            number: _this.data.number,
            current: _this.data.current
        }, function (result) {
            var res = result.data.records
            _this.setData({
                newsListX: res
            });
        })
    },

    //更多
    more: function (e) {
        wx.navigateTo({
            url: '/pages/morelist/morelist?title=' + e.currentTarget.dataset.title,
        })
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    onShareAppMessage: function () {

    }
})